package com.lee.dutylower.db.greenEntity;


import com.lee.dutylower.db.BaseDB;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinEntity;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import com.lee.dutylower.db.greendao.DaoSession;
import com.lee.dutylower.db.greendao.SoldierDao;
import com.lee.dutylower.db.greendao.SentryDao;

/**
 * Created by lijie on 2017/4/18.
 */
@Entity
public class Sentry extends BaseDB {
    @Id
    private Long sentry_id;
    @Property
    private String sentry_name;
    @Property
    private Integer sentry_type;

    @ToMany
    @JoinEntity(entity = SoldierSentry.class,sourceProperty = "sentryId",targetProperty = "soldierId")
    private List<Soldier> soldiers;
    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;
    /** Used for active entity operations. */
    @Generated(hash = 1586976850)
    private transient SentryDao myDao;

    @Generated(hash = 945075077)
    public Sentry(Long sentry_id, String sentry_name, Integer sentry_type) {
        this.sentry_id = sentry_id;
        this.sentry_name = sentry_name;
        this.sentry_type = sentry_type;
    }

    @Generated(hash = 1799852426)
    public Sentry() {
    }

    public Long getSentry_id() {
        return this.sentry_id;
    }

    public void setSentry_id(Long sentry_id) {
        this.sentry_id = sentry_id;
    }

    public String getSentry_name() {
        return this.sentry_name;
    }

    public void setSentry_name(String sentry_name) {
        this.sentry_name = sentry_name;
    }

    public Integer getSentry_type() {
        return this.sentry_type;
    }

    public void setSentry_type(Integer sentry_type) {
        this.sentry_type = sentry_type;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 523252439)
    public List<Soldier> getSoldiers() {
        if (soldiers == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            SoldierDao targetDao = daoSession.getSoldierDao();
            List<Soldier> soldiersNew = targetDao._querySentry_Soldiers(sentry_id);
            synchronized (this) {
                if (soldiers == null) {
                    soldiers = soldiersNew;
                }
            }
        }
        return soldiers;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1467588108)
    public synchronized void resetSoldiers() {
        soldiers = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 827260960)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getSentryDao() : null;
    }
}
